""" F(x) -> y """
from common import *
from pylab import *
import sys

default_data = 'sin(x)'

def setup(data = default_data):
    import wx
    ok = False
    error_msg = ''
    func = data
    while not ok:
        dlg = wx.TextEntryDialog(None, error_msg + 'f(x) = ', 'Configure Process', func)
        
        if dlg.ShowModal() == wx.ID_OK:
            func = dlg.GetValue()
            try:
                x = arange(1.0,2.0,0.1)
                y = eval(func)
                data = func
                ok = True
            except Exception, e:
                error_msg = str(e) + '\n'
        else:
            ok = True
        dlg.Destroy()
    return data

def F_xFunc(x_in, y, data = default_data):
    while True:
        x = x_in()

        if (type(x) == tuple):
            job_id = x[0]
            x = x[1]
            job = eval(data)
            y((job_id,job))
        else:
            y(eval(data))
